package com.example.klaraservice.service.impl;

import com.example.klaraservice.dao.UserMapper;
import com.example.klaraservice.pojo.User;
import com.example.klaraservice.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : Glacialerisa
 * @date : 2023/6/1 15:19
 * @desc :
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectAllLikeNickName(String name) {
        return userMapper.selectAllLikeNickName(name);
    }
    @Override
    public User selectByPhone(String phone){
        return userMapper.selectByPhone(phone);
    }
    @Override
    public User login(String phone,String password) {
        return userMapper.selectUserByPhoneAndPassword(phone, password);
    }

    @Override
    public boolean logout() {
        return false;
    }

    @Override
    public boolean register(String phone,String password) {
        String uuid="";
        return  userMapper.addUserByPhoneAndUuid(phone,password,uuid);
    }
    @Override
    public Map<String, Object> selectAll(int pageNum, int pageSize, String name){
        //通过PageHelper对象设定分页参数
        PageHelper.startPage(pageNum, pageSize);
        //当前页面的数据
        List<User> list = userMapper.selectAllLikeNickName(name);
        //创建PageInfo对象，并将当前页面数据传入，计算分页相关数据
        PageInfo<User> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        Map<String, Object> map = new HashMap<>();
        //本页数据
        map.put("list", list);
        //总数据条目
        map.put("total", total);
        return map;

    }

    @Override
    public boolean updateUserInfo(User user) {
        boolean b = userMapper.updateUserInfo(user);
        return false;
    }
}
